package org.darkforest.merchant.controller;

import org.apache.commons.lang3.StringUtils;
import org.darkforest.common.util.AliOssFileUploadUtil;
import org.darkforest.common.util.DateUtil;
import org.darkforest.controller.WebController;
import org.darkforest.dao.mapper.*;
import org.darkforest.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by lenovo on 2015/6/16.
 */
@Controller
@RequestMapping("website")
public class ArticleController extends WebController<ArticleController> {
    @Autowired
    private ArticleClassMapper articleClassMapper;
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private AdvPositionMapper adMapper;
    @Autowired
    private AdvMapper advMapper;
    @Autowired
    private GoodsClassMapper goodsClassMapper;

    /**
     * 文章分类列表
     * @return
     */
    @RequestMapping("articleClass")
    public ModelAndView articleClass(){
        ModelAndView modelAndView =new ModelAndView("website/article_class_list");
        List<ArticleClass> articleClassesList = articleClassMapper.selectAllArticleClass();
        modelAndView.addObject("articleClassesList", articleClassesList);
        return modelAndView;
    }
    /**
     * to-------增加品牌
     * @return
     */
    @RequestMapping("articleClass/toAdd")
    public ModelAndView toAddArticleClass(String acParentId){
        ModelAndView modelAndView = new ModelAndView("website/article_class_add");
        ArticleClass articleClass = new ArticleClass();
        articleClass.setAcParentId(0);
        List<ArticleClass> articleClassList =articleClassMapper.findArticleClassByCondition(articleClass);
        modelAndView.addObject("articleClassList", articleClassList);
        if(null != acParentId && !"".equals(acParentId)){
            modelAndView.addObject("acParentId",acParentId);
        }
        return modelAndView;
    }

    /**
     * 文章分类名称检查是否重复
     * @return
     */
    @RequestMapping("articleClass/checkArticleClassName")
    public @ResponseBody boolean checkArticleClassName(String acName,String acId){
        ArticleClass articleClass = new ArticleClass();
        articleClass.setAcName(acName);
        if(null!=acId && !"".equals(acId)){
            articleClass.setAcId(Integer.parseInt(acId));
        }
        List<ArticleClass> articleClassList = this.articleClassMapper.findCheckArticleClassNamesByCondition(articleClass);
        if(articleClassList.size()>0){
            return false;
        }else{
            return true;
        }
    }
    /**
     * do------新增品牌
     */
    @RequestMapping("articleClass/doAdd")
    public ModelAndView addArticleClass(MultipartHttpServletRequest multipartHttpServletRequest){

        ModelAndView modelAndView = new ModelAndView("message");
        ArticleClass articleClass = new ArticleClass();
        articleClass.setAcName(multipartHttpServletRequest.getParameter("acName"));
        articleClass.setAcCode(multipartHttpServletRequest.getParameter("acCode"));
        articleClass.setAcParentId(multipartHttpServletRequest.getParameter("acParentId") == null ? 0 : Integer.parseInt(multipartHttpServletRequest.getParameter("acParentId")));
        articleClass.setAcSort(Integer.parseInt(multipartHttpServletRequest.getParameter("acSort")));

        int i =articleClassMapper.insert(articleClass);
        if(i>0){
            modelAndView.addObject("msg","文章分类新增成功");
        }else{
            modelAndView.addObject("msg","文章分类新增失败");
        }
        return modelAndView;
    }

    @RequestMapping("articleClass/toModify")
    public ModelAndView toModifyArticleClass(Integer acId){
        ModelAndView modelAndView = new ModelAndView("website/article_class_modify");
        ArticleClass articleClass = this.articleClassMapper.selectByPrimaryKey(acId);
        modelAndView.addObject("articleClass", articleClass);
        return modelAndView;
    }

    @RequestMapping("articleClass/doModify")
    public ModelAndView doModifyArticleClass(MultipartHttpServletRequest multipartHttpServletRequest){
        ModelAndView modelAndView = new ModelAndView("message");
        ArticleClass articleClass = new ArticleClass();
        articleClass.setAcId(multipartHttpServletRequest.getParameter("acId") == null ? 0 : Integer.parseInt(multipartHttpServletRequest.getParameter("acId")));
        articleClass.setAcName(multipartHttpServletRequest.getParameter("acName"));
        articleClass.setAcCode(multipartHttpServletRequest.getParameter("acCode"));
        articleClass.setAcParentId(multipartHttpServletRequest.getParameter("acParentId") == null ? 0 : Integer.parseInt(multipartHttpServletRequest.getParameter("acParentId")));
        articleClass.setAcSort(Integer.parseInt(multipartHttpServletRequest.getParameter("acSort")));
        int i =articleClassMapper.updateByPrimaryKeySelective(articleClass);
        if(i>0){
            modelAndView.addObject("msg","文章分类修改成功");
        }else{
            modelAndView.addObject("msg","文章分类修改失败");
        }
        return modelAndView;
    }

    @RequestMapping("articleClass/delArticleClass")
    public  ModelAndView delArticleClass(HttpServletRequest request){
        String[] acIds = request.getParameterValues("acId");
        int i=0;
        for(String id :acIds ){
            i+= articleClassMapper.deleteByPrimaryKey(Integer.parseInt(id));
        }
        ModelAndView modelAndView = new ModelAndView("message");
        if(i==acIds.length){
            modelAndView.addObject("msg","文章分类删除成功");
        }else{
            modelAndView.addObject("msg","文章分类删除失败");
        }
        return modelAndView;
    }
    /**
     * 字符编码格式化UTF-8
     * @param str
     * @return
     */
    public static String encodeStr(String str) {
        try {
            return new String(str.getBytes("ISO-8859-1"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 文章列表
     * @return
     */
    @RequestMapping("article")
    public ModelAndView article(){
        ModelAndView modelAndView =new ModelAndView("website/article_list");
//        List<Article> articleList = this.articleMapper.selectAllArticle();
//        modelAndView.addObject("articleList", articleList);
        Article page = new Article();
        page.setResultList(this.articleMapper.findArticleByCondition(page));
        modelAndView.addObject("page", page);
        ArticleClass articleClass = new ArticleClass();
        articleClass.setAcParentId(0);
        List<ArticleClass> articleClassParentList = articleClassMapper.findArticleClassByCondition(articleClass);
        modelAndView.addObject("articleClassParentList",articleClassParentList);
        List<ArticleClass> articleClassSonList = articleClassMapper.findArticleClassSonByCondition();
        modelAndView.addObject("articleClassSonList",articleClassSonList);
        return modelAndView;
    }
    /**
     * 高级查询文章列表
     * @return
     */
    @RequestMapping("article/searchArticle")
    public ModelAndView searchBrand(Article article,HttpServletRequest request){
        String articleTitle = request.getParameter("articleTitle");
        String acId = request.getParameter("acId");
        if(articleTitle!= null &&!articleTitle.equals("")){
            article.setArticleTitle(articleTitle);
        }
        if(acId!= null &&!acId.equals("")){
            article.setAcId(Integer.parseInt(acId));
        }
        ModelAndView modelAndView =new ModelAndView("website/article_list");
//        List<Article> articleList = articleMapper.findArticleByCondition(article);
//        modelAndView.addObject("articleList",articleList);
        article.setResultList(this.articleMapper.findArticleByCondition(article));
        modelAndView.addObject("page",article);
        modelAndView.addObject("articleTitle", articleTitle);
        modelAndView.addObject("acId",acId);
        ArticleClass articleClass = new ArticleClass();
        articleClass.setAcParentId(0);
        List<ArticleClass> articleClassParentList = articleClassMapper.findArticleClassByCondition(articleClass);
        modelAndView.addObject("articleClassParentList",articleClassParentList);
        List<ArticleClass> articleClassSonList = articleClassMapper.findArticleClassSonByCondition();
        modelAndView.addObject("articleClassSonList",articleClassSonList);
        return modelAndView;
    }
    /**
     * to-------增加品牌
     * @return
     */
    @RequestMapping("article/toAdd")
    public ModelAndView articleAdd(String acId){
        ModelAndView modelAndView = new ModelAndView("website/article_add");
        ArticleClass articleClass = new ArticleClass();
        articleClass.setAcParentId(0);
        List<ArticleClass> articleClassParentList = articleClassMapper.findArticleClassByCondition(articleClass);
        modelAndView.addObject("articleClassParentList",articleClassParentList);
        List<ArticleClass> articleClassSonList = articleClassMapper.findArticleClassSonByCondition();
        modelAndView.addObject("articleClassSonList",articleClassSonList);
        if(null != acId && !"".equals(acId)){
            modelAndView.addObject("acId",acId);
        }
        return modelAndView;
    }

    /**
     * 品牌名称检查是否重复
     * @return
     */
    @RequestMapping("article/ajaxFileUpload")
    public  @ResponseBody String checkBrandName(MultipartHttpServletRequest multipartHttpServletRequeste, HttpServletResponse response) throws IOException {
        MultipartFile BrandPicturempf = multipartHttpServletRequeste.getFile("articlePicture");
        String articlePicture = super.uploadPicsWithoutCompressSize(BrandPicturempf, multipartHttpServletRequeste, null, null);
        //返回结果
//        String res = "{ error:'ok', articlePicture:'" + articlePicture + "',imgurl:'" + articlePicture + "'}";
//        response.getWriter().print(res);
        return articlePicture;
    }
    /**
     * do------新增品牌
     */
    @RequestMapping("article/doAdd")
    public ModelAndView doAddArticle(MultipartHttpServletRequest multipartHttpServletRequest){
        ModelAndView modelAndView = new ModelAndView("message");
        Article article = new Article();
        article.setArticleTitle(multipartHttpServletRequest.getParameter("articleTitle"));
        article.setAcId(Integer.parseInt(multipartHttpServletRequest.getParameter("acId")));
        article.setArticleUrl(multipartHttpServletRequest.getParameter("articleUrl"));
        article.setArticleContent(multipartHttpServletRequest.getParameter("articleContent"));
        String sort = multipartHttpServletRequest.getParameter("articleSort");
        article.setArticleSort((sort==null || StringUtils.isEmpty(sort))?99:Integer.parseInt(sort));
        article.setArticleShow(multipartHttpServletRequest.getParameter("articleShow") .equals("1") ? true : false);
        String[] articlePictures = multipartHttpServletRequest.getParameterValues("articlePicture");
        String articlePicture = null;
        if(articlePictures!=null && articlePictures.length>0){
            for(int i=0;i<articlePictures.length;i++){
                if(i==0){
                    articlePicture = articlePictures[i];
                }else{
                    articlePicture += ","+ articlePictures[i];
                }
            }
        }
        article.setArticlePicture(articlePicture);
        article.setArticleTime(DateUtil.unixTimeStampInt().intValue());
        int i = articleMapper.insert(article);
        if(i>0){
            modelAndView.addObject("msg","文章新增成功");
        }else{
            modelAndView.addObject("msg","文章新增失败");
        }
        return modelAndView;
    }

    @RequestMapping("article/toModify")
    public ModelAndView toModifyArticle(Integer articleId){
        ModelAndView modelAndView = new ModelAndView("website/article_modify");
        Article article = this.articleMapper.selectByPrimaryKey(articleId);
        modelAndView.addObject("article", article);
        if(article.getArticlePicture()!=null){
            List <String> articlePictures = new ArrayList<String>();
            for(int i=0;i<article.getArticlePicture().split(",").length;i++){
                articlePictures.add(article.getArticlePicture().split(",")[i]);
            }
            modelAndView.addObject("articlePictures",articlePictures);
        }
        ArticleClass articleClass = new ArticleClass();
        articleClass.setAcParentId(0);
        List<ArticleClass> articleClassParentList = articleClassMapper.findArticleClassByCondition(articleClass);
        modelAndView.addObject("articleClassParentList", articleClassParentList);
        List<ArticleClass> articleClassSonList = articleClassMapper.findArticleClassSonByCondition();
        modelAndView.addObject("articleClassSonList",articleClassSonList);
        modelAndView.addObject("acId",article.getAcId());
        return modelAndView;
    }

    @RequestMapping("article/doModify")
    public ModelAndView doModifyArticle(MultipartHttpServletRequest multipartHttpServletRequest){
        ModelAndView modelAndView = new ModelAndView("message");
        Article article = new Article();
        article.setArticleTitle(multipartHttpServletRequest.getParameter("articleTitle"));
        article.setAcId(Integer.parseInt(multipartHttpServletRequest.getParameter("acId")));
        article.setArticleUrl(multipartHttpServletRequest.getParameter("articleUrl"));
        article.setArticleContent(multipartHttpServletRequest.getParameter("articleContent"));
        article.setArticleSort(Integer.parseInt(multipartHttpServletRequest.getParameter("articleSort")));
        article.setArticleShow(multipartHttpServletRequest.getParameter("articleShow").equals("1") ? true : false);
        String[] articlePictures = multipartHttpServletRequest.getParameterValues("articlePicture");
        String articlePicture = null;
        if(articlePictures!=null && articlePictures.length>0){
            for(int i=0;i<articlePictures.length;i++){
                if(i==0){
                    articlePicture = articlePictures[i];
                }else{
                    articlePicture += ","+ articlePictures[i];
                }
            }
        }
        article.setArticlePicture(articlePicture);
        article.setArticleId(Integer.parseInt(multipartHttpServletRequest.getParameter("articleId")));
        int i =articleMapper.updateByPrimaryKeySelective(article);
        if(i>0){
            modelAndView.addObject("msg","文章修改成功");
        }else{
            modelAndView.addObject("msg","文章修改失败");
        }
        return modelAndView;
    }
    @RequestMapping("article/delArticle")
    public  ModelAndView delArticle(HttpServletRequest request){
        String[] articleId = request.getParameterValues("articleId");
        int i=0;
        for(String id :articleId ){
            i+= articleMapper.deleteByPrimaryKey(Integer.parseInt(id));
        }
        ModelAndView modelAndView = new ModelAndView("message");
        if(i==articleId.length){
            modelAndView.addObject("msg","文章删除成功");
        }else{
            modelAndView.addObject("msg","文章删除失败");
        }
        return modelAndView;
    }


    @RequestMapping("ad")
    public ModelAndView adList(AdvPositionBean adSearchBean){
        List list = adMapper.selectByCondition(adSearchBean);
        adSearchBean.setResultList(list);
        ModelAndView modelAndView = new ModelAndView("website/adList", "page", adSearchBean);
        return modelAndView;
    }

    @RequestMapping("ad/adAdd")
    public ModelAndView adAdd(){
        ModelAndView modelAndView = new ModelAndView("website/ad_add");
        GoodsClass goodsClass = new GoodsClass();
        goodsClass.setGcParentId(0);
        goodsClass.setPageSwitch(false);
        List<GoodsClass> goodsClassList = goodsClassMapper.findGoodsClass(goodsClass);
        modelAndView.addObject("goodsClassList", goodsClassList);
        return modelAndView;
    }

    /**
     * 广告位编辑
     * @return
     */
    @RequestMapping("ad/adEdit")
    public ModelAndView adEdit(HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView("website/ad_edit");
        String id = request.getParameter("apId");
        AdvPosition adv = adMapper.selectByPrimaryKey(Integer.valueOf(id));
        modelAndView.addObject("adv",adv);
        GoodsClass goodsClass = new GoodsClass();
        goodsClass.setGcParentId(0);
        goodsClass.setPageSwitch(false);
        List<GoodsClass> goodsClassList = goodsClassMapper.findGoodsClass(goodsClass);
        modelAndView.addObject("goodsClassList", goodsClassList);
        return modelAndView;
    }

    /**
     * 广告位编辑
     * @param ad
     * @param default_pic 上传图片参数
     * @param request
     * @return
     */
    @RequestMapping("ad/doAdEdit")
    public ModelAndView doAdEdit(AdvPosition ad,MultipartFile default_pic,HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView("redirect:/website/ad");
        if(ad.getApClass()==0||ad.getApClass()==3){
            ad.setAdvNum(0);
            ad.setApPrice(0);
            ad.setClickNum(0);
            if(default_pic!=null&&default_pic.getOriginalFilename()!=null&&!"".equals(default_pic.getOriginalFilename())){
                String end =  default_pic.getOriginalFilename().substring(default_pic.getOriginalFilename().lastIndexOf("."));
                String name = new Date().getTime()+"."+end;
                String begin = System.getProperty("user.dir");
                File targetFile = new File(begin,name);
                try {
                    default_pic.transferTo(targetFile);
                    AliOssFileUploadUtil.uploadPic(new Date().getTime() + "", name, targetFile);
                    ad.setDefaultContent(name);
                    ad.setAdvNum(0);
                } catch (IOException e) {
                    request.setAttribute("message","保存文件失败，请查看!");
                    e.printStackTrace();
                }
            }
        }else{
            ad.setApWidth(0);
            ad.setApHeight(0);
            ad.setApPrice(0);
            ad.setClickNum(0);
        }
        adMapper.updateByPrimaryKey(ad);
        return modelAndView;
    }

    @RequestMapping("ad/doAdAdd")
    public ModelAndView doAdAdd(AdvPosition ad,MultipartFile default_pic,HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView("redirect:/website/ad");
        if(ad.getApClass()==0||ad.getApClass()==3){
            ad.setAdvNum(0);
            ad.setApPrice(0);
            ad.setClickNum(0);
            if(default_pic!=null&&default_pic.getOriginalFilename()!=null&&!"".equals(default_pic.getOriginalFilename())){
                String end =  default_pic.getOriginalFilename().substring(default_pic.getOriginalFilename().lastIndexOf("."));
                String name = new Date().getTime()+"."+end;
                String begin = System.getProperty("user.dir");
                File targetFile = new File(begin,name);
                try {
                    default_pic.transferTo(targetFile);
                    AliOssFileUploadUtil.uploadPic(new Date().getTime() + "", name, targetFile);
                    ad.setDefaultContent(name);
                    ad.setAdvNum(0);
                } catch (IOException e) {
                    request.setAttribute("message","保存文件失败，请查看!");
                    e.printStackTrace();
                }
            }
        }else{
            ad.setApWidth(0);
            ad.setApHeight(0);
            ad.setAdvNum(0);
            ad.setApPrice(0);
            ad.setAdvNum(0);
            ad.setClickNum(0);
        }
        adMapper.insertSelective(ad);
        return modelAndView;
    }

    @RequestMapping("ad/deleteAd")
    public ModelAndView deleteAd(HttpServletRequest request){
        String[] ids = request.getParameterValues("ids");
        int i=0;
        for(String id :ids ){
            i+= adMapper.deleteByPrimaryKey(Integer.parseInt(id));
        }
        ModelAndView modelAndView = new ModelAndView("message");
        if(i==ids.length){
            modelAndView.addObject("msg", "删除广告位成功");
        }else{
            modelAndView.addObject("msg", "删除广告位失败");
        }
        return modelAndView;
    }


    @RequestMapping("ad/editUsed")
    public ModelAndView editUsed(int id,Short used){
        ModelAndView modelAndView = new ModelAndView("redirect:/website/ad");
        AdvPosition adv = adMapper.selectByPrimaryKey(id);
        adv.setIsUse(used);
        adMapper.updateByPrimaryKeySelective(adv);
        return modelAndView;
    }



    @RequestMapping("ad/ggList")
    public ModelAndView ggList(AdvBean advBean){
        List list = advMapper.selectByCondition(advBean);
        advBean.setResultList(list);
        ModelAndView modelAndView = new ModelAndView("website/ggList","page",advBean);
        AdvPosition position = adMapper.selectByPrimaryKey(advBean.getApId());
        modelAndView.addObject("ad", position);
        return modelAndView;
    }

    @RequestMapping("ad/addgg")
    public ModelAndView addgg(int apId){
        ModelAndView modelAndView = new ModelAndView("website/gg_add");
        List advList = adMapper.selectByCondition(new AdvPositionBean());
        modelAndView.addObject("advList",advList);
        modelAndView.addObject("apId",apId);
        return modelAndView;
    }

    /**
     * 广告编辑
     * @param apId
     * @return
     */
    @RequestMapping("ad/ggEdit")
    public ModelAndView ggEdit(int apId,int advId){
        ModelAndView modelAndView = new ModelAndView("website/gg_edit");
        AdvPosition advPosition = adMapper.selectByPrimaryKey(apId);
        Adv adv = advMapper.selectByPrimaryKey(advId);
        modelAndView.addObject("ap",advPosition);
        modelAndView.addObject("adv",adv);
        modelAndView.addObject("apId",apId);
        return modelAndView;
    }


    /**
     * 修改广告
     * @param adv
     * @return
     */
    @RequestMapping(value = "modifyAdv")
    public @ResponseBody boolean modifyAdv(Adv adv){
        advMapper.updateByPrimaryKeySelective(adv);
        return true;
    }

    /**
     * 广告编辑
     * @param adv
     * @param oldApId
     * @param appType
     * @param adv_start_time
     * @param adv_end_time
     * @param adv_pic
     * @param request
     * @return
     */
    @RequestMapping("ad/ggDoEdit")
    public ModelAndView ggDoEdit(Adv adv,int oldApId,String appType,String adv_start_time,String adv_end_time,MultipartFile adv_pic,HttpServletRequest request){
        int advStartTime = DateUtil.toUnixTimeStampByDate(adv_start_time);
        int advEndTime = DateUtil.toUnixTimeStampByDate(adv_end_time);
        adv.setApId(oldApId);
        adv.setAdvStartDate(advStartTime);
        adv.setAdvEndDate(advEndTime);
        adv.setSlideSort(0);
        adv.setMemberId(0);
        adv.setMemberName("test");
        adv.setClickNum(0);
        adv.setIsAllow(Short.parseShort("1"));
        adv.setGoldpay(1);
        adv.setBuyStyle("wang");
        if("0".equals(appType)||"3".equals(appType)){
            if(adv_pic!=null&&adv_pic.getOriginalFilename()!=null&&!"".equals(adv_pic.getOriginalFilename())){
                String end =  adv_pic.getOriginalFilename().substring(adv_pic.getOriginalFilename().lastIndexOf("."));
                String name = new Date().getTime()+end;
                String begin = System.getProperty("user.dir");
                File targetFile = new File(begin,name);
                try {
                    adv_pic.transferTo(targetFile);
                    AliOssFileUploadUtil.uploadPic(new Date().getTime() + "", name, targetFile);
                    adv.setAdvContent(name);
                } catch (IOException e) {
                    request.setAttribute("message","保存文件失败，请查看!");
                    e.printStackTrace();
                }
            }
        }
        advMapper.updateByPrimaryKey(adv);
        ModelAndView modelAndView = new ModelAndView("redirect:/website/ad/ggList?apId="+oldApId);
        return modelAndView;
    }

    @RequestMapping("ad/doaddgg")
    public ModelAndView doaddgg(Adv adv,int oldApId,String appType,String adv_start_time,String adv_end_time,String advUrl,MultipartFile adv_pic,HttpServletRequest request){
        int advStartTime = DateUtil.toUnixTimeStampByDate(adv_start_time);
        int advEndTime = DateUtil.toUnixTimeStampByDate(adv_end_time);
        adv.setAdvStartDate(advStartTime);
        adv.setAdvEndDate(advEndTime);
        adv.setSlideSort(0);
        adv.setMemberId(0);
        adv.setMemberName("test");
        adv.setClickNum(0);
        adv.setIsAllow(Short.parseShort("1"));
        adv.setAdvUrl(advUrl);

        adv.setGoldpay(1);
        adv.setBuyStyle("wang");
        if("0".equals(appType)||"3".equals(appType)){
            if(adv_pic!=null&&adv_pic.getOriginalFilename()!=null&&!"".equals(adv_pic.getOriginalFilename())){
                String end =  adv_pic.getOriginalFilename().substring(adv_pic.getOriginalFilename().lastIndexOf("."));
                String name = new Date().getTime()+end;
                String begin = System.getProperty("user.dir");
                File targetFile = new File(begin,name);
                try {
                    adv_pic.transferTo(targetFile);
                    AliOssFileUploadUtil.uploadPic(new Date().getTime() + "", name, targetFile);
                    adv.setAdvContent(name);
                } catch (IOException e) {
                    request.setAttribute("message","保存文件失败，请查看!");
                    e.printStackTrace();
                }
            }
        }
        advMapper.insertSelective(adv);
        ModelAndView modelAndView = new ModelAndView("redirect:/website/ad/ggList?apId="+oldApId);
        return modelAndView;
    }




    @RequestMapping("ad/deleteGG")
    public ModelAndView deleteGG(int apId,int advId){
        advMapper.deleteByPrimaryKey(advId);
        ModelAndView modelAndView = new ModelAndView("redirect:/website/ad/ggList?apId="+apId);
        return modelAndView;
    }
}
